package com.tidc.consumer8001.controller;

import com.tidc.api.pojo.UserOV;
import com.tidc.api.pojo.user.User;
import com.tidc.consumer8001.service.UserManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassNmae UserManagerController
 * @Description TODO
 * @Author 冯涛滔
 **/
@RestController
@CrossOrigin
public class UserManagerController {
	@Autowired
	private UserManagerService userManagerService;
	/**
	 * 注册一个账号
	 * @param teacher
	 * @return
	 */
	@PostMapping("/register")
	public UserOV register(@RequestBody User teacher){
		return userManagerService.register(teacher);
	}

	/**
	 * 开关老师的权限
	 * @param teacher email
	 * @return
	 */
	@PutMapping("/teacher/switch")
	public UserOV switchTeacher(@RequestBody User teacher,HttpServletRequest req){
		return userManagerService.switchTeacher(teacher,req);
	}

//	/**
//	 * @param email
//	 * @return 根据邮箱号返回用户详细信息
//	 */
//	@GetMapping("/usermanager/user/info")
//	public UserOV userInfo(@RequestParam("email") String email){
//		return userManagerService.userInfo(email);
//	}

	/**
	 * 根据学校id查询该学校的所有学生信息(通过token获取id)
	 * @param req
	 * @return
	 */
	@GetMapping("/school/student")
	public UserOV<List<User>> listSchoolStudent(HttpServletRequest req){
		return userManagerService.listSchoolStudent(req);
	}

	/**
	 * 使用学生id查询他们的email
	 * @param list
	 * @return
	 */
	@GetMapping("/list/student/email")
	public UserOV<List<String>> listStudentEmail(@RequestParam("list") List<Integer> list){
		return userManagerService.listStudentEmail(list);
	}

	/**
	 * 使用email查看student信息
	 * @param email
	 * @return
	 */
	@GetMapping("/student")
	public UserOV<User> getStudent(@RequestParam("email") String email){
		return userManagerService.getStudent(email);
	}


}
